﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class PG5:Group
    {
        public PG5()
        {
                m_ps = new List<SpecisOutput>();

            m_ps.Add(new SpecisOutput("SO2", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("NOX", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("HNO3", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("NO", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("NO2", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("ODOR", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("TOLUENE", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("XYLENE", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("B-PINENE", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("A-PINENE", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("SO4", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("NO3", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("PM10", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("SOA", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("H2O", false, true, false, true, false, true, false));
            m_ps.Add(new SpecisOutput("TXS", false, true, false, true, false, true, false));
            m_ps[0].CalculateSpecies = true;
        }



          // Fields
     
     
        /// <summary>
        /// 是否输出浓度场CONC.DAT。=0，不输出=1，输出
        /// </summary>
       private int m_ICON = 1;

       public int ICON
       {
           get { return m_ICON; }
           set { m_ICON = value; }
       }
       /// <summary>
       /// 是否输出干沉积文件DFLX.DAT。=0，不输出=1，输出
       /// </summary>
       private int m_IDRY = 1;

       public int IDRY
       {
           get { return m_IDRY; }
           set { m_IDRY = value; }
       }

       /// <summary>
       /// 是否输出湿干沉积文件WDFLX.DAT。=0，不输出=1，输出
       /// </summary>
       private int m_IWET = 1;

       public int IWET
       {
           get { return m_IWET; }
           set { m_IWET = value; }
       }

      /// <summary>
       /// 是否输出2d温度文件。=0，不输出=1，输出
      /// </summary>
       private int m_IT2D = 0;

       public int IT2D
       {
           get { return m_IT2D; }
           set { m_IT2D = value; }
       }
       /// <summary>
       /// 是否输出2d温度密度文件。=0，不输出=1，输出
       /// </summary>
       private int m_IRHO =0;

       public int IRHO
       {
           get { return m_IRHO; }
           set { m_IRHO = value; }
       }

       /// <summary>
       /// 是否输出相对湿度文件。=0，不输出=1，输出
       /// </summary>
       private int m_IVIS = 0;

       public int IVIS
       {
           get { return m_IVIS; }
           set { m_IVIS = value; }
       }

       /// <summary>
       /// 是否压缩输出文件。=0，不输出=1，输出
       /// </summary>
       private bool m_LCOMPRS = true;

       public bool LCOMPRS
       {
           get { return m_LCOMPRS; }
           set { m_LCOMPRS = value; }
       }
      /// <summary>
       /// 输出一系列文件用来作图。=0，不输出=1，输出
      /// </summary>
       private int m_IQAPLOT = 1;

       public int IQAPLOT
       {
           get { return m_IQAPLOT; }
           set { m_IQAPLOT = value; }
       }

     /// <summary>
       ///  是否输出穿过用户自定义边界层的质量通量(MASSFLAX.DAT)
     /// </summary>
       private int m_IMFLX = 0;

       public int IMFLX
       {
           get { return m_IMFLX; }
           set { m_IMFLX = value; }
       }

    
/// <summary>
       ///   是否输出质量平衡结果文件（MASSBAL.DAT）
/// </summary>
       private int m_IMBAL = 0;

       public int IMBAL
       {
           get { return m_IMBAL; }
           set { m_IMBAL = value; }
       }


  
        /// <summary>
       /// 是否输出烟羽抬升高度文件,仅在单个点源时应用
        /// </summary>
       private int m_INRISE = 0;

       public int INRISE
       {
           get { return m_INRISE; }
           set { m_INRISE = value; }
       }

       /// <summary>
       /// 是否在CALPUFF.LST文件中输出浓度
       /// </summary>
       private int m_ICPRT = 0;

       public int ICPRT
       {
           get { return m_ICPRT; }
           set { m_ICPRT = value; }
       }

      /// <summary>
       /// 是否在CALPUFF.LST文件中输出干沉积
      /// </summary>
       private int m_IDPRT = 0;

       public int IDPRT
       {
           get { return m_IDPRT; }
           set { m_IDPRT = value; }
       }

       /// <summary>
       /// 是否在CALPUFF.LST文件中输出湿沉积
       /// </summary>
       private int m_IWPRT = 0;

       public int IWPRT
       {
           get { return m_IWPRT; }
           set { m_IWPRT = value; }
       }

       /// <summary>
       /// 输出浓度的时间间隔，单位小时
       /// </summary>
       private int m_ICFRQ = 1;

       public int ICFRQ
       {
           get { return m_ICFRQ; }
           set { m_ICFRQ = value; }
       }
       /// <summary>
       /// 输出干沉积浓度的时间间隔，单位小时
       /// </summary>
       private int m_IDFRQ = 1;

       public int IDFRQ
       {
           get { return m_IDFRQ; }
           set { m_IDFRQ = value; }
       }
      /// <summary>
       /// 输出湿沉积的时间间隔，单位小时
      /// </summary>
       private int m_IWFRQ = 1;

       public int IWFRQ
       {
           get { return m_IWFRQ; }
           set { m_IWFRQ = value; }
       }

      /// <summary>
       /// 浓度和沉积量的单位
       /// 1 = g/m**3 g/m**2/s
       /// 2 = mg/m**3 mg/m**2/s
       /// 3 = ug/m**3 ug/m**2/s
       /// 4 = ng/m**3 ng/m**2/s
       /// 5 = Odour Units
              /// </summary>
       private int m_IPRTU=3;

       public int IPRTU
       {
           get { return m_IPRTU; }
           set { m_IPRTU = value; }
       }
      /// <summary>
       /// 跟踪运行过程的信息是否显示在屏幕上
       ///   0 = no
       ///   1 = yes (advection step, puff ID)
       ///   2 = yes (YYYYJJJHH, # old puffs, # emitted puffs)
      /// </summary>
       private int m_IMESG = 2;

       public int IMESG
       {
           get { return m_IMESG; }
           set { m_IMESG = value; }
       }
       
        /// <summary>
       /// SPECIES (or GROUP for combined species) LIST FOR OUTPUT OPTIONS
        /// </summary>
       List<SpecisOutput> m_ps;

       public List<SpecisOutput> Ps
       {
           get { return m_ps; }
           set { m_ps = value; }
       }

       /// <summary>
       /// 是否输出debug的信息.F or T
       /// </summary>
       private bool m_LDEBUG = false;

       public bool LDEBUG
       {
           get { return m_LDEBUG; }
           set { m_LDEBUG = value; }
       }

     /// <summary>
       ///调试选项中第一个追踪的烟团的编号，只在LDEBUG=T时，有效
     /// </summary>
       private int m_IPFDEB = 1;

       public int IPFDEB
       {
           get { return m_IPFDEB; }
           set { m_IPFDEB = value; }
       }

       
        /// <summary>
        /// 调试选项中追踪的烟团的数量，只在LDEBUG=T时，有效
        /// </summary>
       private int m_NPFDEB = 1;

       public int NPFDEB
       {
           get { return m_NPFDEB; }
           set { m_NPFDEB = value; }
       }

       
        /// <summary>
        /// 开始调试输出的时间
        /// </summary>
       private int m_NN1 = 1;

       public int NN1
       {
           get { return m_NN1; }
           set { m_NN1 = value; }
       }
       //终止调试输出的时间
       private int m_NN2 = 10;

       public int NN2
       {
           get { return m_NN2; }
           set { m_NN2 = value; }
       }


       public override void ReadFromGroup(Dictionary<string, string> dic)
       {
           foreach (KeyValuePair<string, string> m_dic in dic)
           {
               if (m_dic.Key == "ICON")
               {
                   this.ICON = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IDRY")
               {
                   this.IDRY = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IWET")
               {
                   this.IWET = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IT2D")
               {
                   this.IT2D = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IRHO")
               {
                   this.IRHO = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IVIS")
               {
                   this.IVIS = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "LCOMPRS")
               {
                   if (m_dic.Value == "T")
                   {
                       this.LCOMPRS = true;
                   }
                   else
                   {
                       this.LCOMPRS = false;
                   }

               }
               if (m_dic.Key == "IQAPLOT")
               {
                   this.IQAPLOT = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IMFLX")
               {
                   this.IMFLX = Convert.ToInt32(m_dic.Value);
               }

               if (m_dic.Key == "IMBAL")
               {
                   this.IMBAL = Convert.ToInt32(m_dic.Value);
               }

               if (m_dic.Key == "INRISE")
               {
                   this.INRISE = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "ICPRT")
               {
                   this.ICPRT = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IDPRT")
               {
                   this.IDPRT = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IWPRT")
               {
                   this.IWPRT = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "ICFRQ")
               {
                   this.ICFRQ = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IDFRQ")
               {
                   this.IDFRQ = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IWFRQ")
               {
                   this.IWFRQ = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "IPRTU")
               {
                   this.IPRTU = Convert.ToInt32(m_dic.Value);
               }
               //
               if (m_dic.Key == "IMESG")
               {
                   this.IMESG = Convert.ToInt32(m_dic.Value);
               }
               if (StrWriter.ReturnBool(m_dic.Key, ",") == true)
               {
                   SpecisOutput s = new SpecisOutput("SO2", false, true, false, true, false, true, false);

                   this.Ps.Add(s.ReadFromGroup(m_dic.Key,m_dic.Value));
               }
              
               if (m_dic.Key == "LDEBUG")
               {
                   if (m_dic.Value == "T")
                   {
                       this.LDEBUG = true;
                   }
                   else
                   {
                       this.LDEBUG = false;
                   }

               }
               if (m_dic.Key == "IPFDEB")
               {
                   this.IPFDEB = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "NPFDEB")
               {
                   this.NPFDEB = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "NN1")
               {
                   this.NN1 = Convert.ToInt32(m_dic.Value);
               }
               if (m_dic.Key == "NN2")
               {
                   this.NN2 = Convert.ToInt32(m_dic.Value);
               }
               
           }
       }
       public override string WriteToGroup()
       {
           string ResultStr = "", TempStr;

           TempStr = StrWriter.GetCLine();
           TempStr += "INPUT GROUP: 5 -- Output Options" + "\r\n";
           ResultStr += TempStr;

           TempStr = StrWriter.GetCLine();
           ResultStr += TempStr;


           TempStr = "! ICON = " + ICON.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IDRY = " + IDRY.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IWET = " + IWET.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IT2D = " + IT2D.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IRHO = " + IRHO.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IVIS = " + IVIS.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           
           

           if (LCOMPRS == true)
           {
               TempStr = "! LCOMPRS = " + "T" + " !" + "\r\n";
           }
           else
           {
               TempStr = "! LCOMPRS = " + "F" + " !" + "\r\n";
           }
           ResultStr += TempStr;

           TempStr = "! IQAPLOT = " + IQAPLOT.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IMFLX = " + IMFLX.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IMBAL = " + IMBAL.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! INRISE = " + INRISE.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! ICPRT = " + ICPRT.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IDPRT = " + IDPRT.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! IWPRT = " + IWPRT.ToString() + " !" + "\r\n";
           ResultStr += TempStr;


           TempStr = "! ICFRQ = " + ICFRQ.ToString() + " !" + "\r\n";
           ResultStr += TempStr;


           TempStr = "! IDFRQ = " + IDFRQ.ToString() + " !" + "\r\n";
           ResultStr += TempStr;


           TempStr = "! IWFRQ = " + IWFRQ.ToString() + " !" + "\r\n";
           ResultStr += TempStr;


           TempStr = "! IPRTU = " + IPRTU.ToString() + " !" + "\r\n";
           ResultStr += TempStr;


           TempStr = "! IMESG = " + IMESG.ToString() + " !" + "\r\n";
           ResultStr += TempStr;
           //
           //

           //进行排序
           List<string> arry = Sort.GetPollutantRightOrder();
           List<SpecisOutput> arrySpecisOutput = new List<SpecisOutput>();
           arrySpecisOutput.Clear();
           foreach (string a in arry)
           {
               for (int i = 0; i < Ps.Count; i++)
               {
                   if (a == Ps[i].Name)
                   {
                       arrySpecisOutput.Add(Ps[i]);
                   }
               }
           }


           //＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝


           for (int i = 0; i < arrySpecisOutput.Count; i++)
           {
               if (arrySpecisOutput[i].CalculateSpecies)
               {
                   TempStr = "!    " + arrySpecisOutput[i].Name + "  =  ";
                   if (arrySpecisOutput[i].ConPrinted == true)
                   {
                       TempStr += "   " + "1" + ",    ";
                   }
                   else
                   {
                       TempStr += "   " + "0" + ",    ";
                   }
                   if (arrySpecisOutput[i].ConSaved == true)
                   {
                       TempStr += "   " + "1" + ",    ";
                   }
                   else
                   {
                       TempStr += "   " + "0" + ",    ";
                   }
                   if (arrySpecisOutput[i].DryPrinted == true)
                   {
                       TempStr += "   " + "1" + ",    ";
                   }
                   else
                   {
                       TempStr += "   " + "0" + ",    ";
                   }
                   if (arrySpecisOutput[i].DrySaved == true)
                   {
                       TempStr += "   " + "1" + ",    ";
                   }
                   else
                   {
                       TempStr += "   " + "0" + ",    ";
                   }
                   if (arrySpecisOutput[i].WetPrinted == true)
                   {
                       TempStr += "   " + "1" + ",    ";
                   }
                   else
                   {
                       TempStr += "   " + "0" + ",    ";
                   }
                   if (arrySpecisOutput[i].WetSaved == true)
                   {
                       TempStr += "   " + "1" + ",    ";
                   }
                   else
                   {
                       TempStr += "   " + "0" + ",    ";
                   }
                   if (arrySpecisOutput[i].MassSaved == true)
                   {
                       TempStr += "   " + "1" + "    !" + "\r\n";
                   }
                   else
                   {
                       TempStr += "   " + "0" + "    !" + "\r\n";
                   }
                   ResultStr += TempStr;
               }
           }
       

           if (LDEBUG == true)
           {
               TempStr = "! LDEBUG = " + "T" + " !" + "\r\n";
           }
           else
           {
               TempStr = "! LDEBUG = " + "F" + " !" + "\r\n";
           }
           ResultStr += TempStr;

           TempStr = "! IPFDEB = " + IPFDEB.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! NPFDEB = " + NPFDEB.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! NN1 = " + NN1.ToString() + " !" + "\r\n";
           ResultStr += TempStr;

           TempStr = "! NN2 = " + NN2.ToString() + " !" + "\r\n";
           ResultStr += TempStr;
          

           ResultStr += "!END!" + "\r\n";

           return ResultStr;
       }



    }



    [Serializable]
    public class SpecisOutput : ICloneable
    {

        public SpecisOutput(string name, bool conPrinted, bool conSaved, bool dryPrinted, bool drySaved, bool wetPrinted, bool wetSaved, bool massSaved)
        {
            this.name = name;
            this.m_ConPrinted = conPrinted;

            this.m_ConSaved = conSaved;

            this.m_DryPrinted = dryPrinted;
            this.m_DrySaved = drySaved;

            this.m_WetPrinted = wetPrinted;

            this.m_WetSaved = wetSaved;

            this.m_MassSaved = massSaved;

        }
        public SpecisOutput ReadFromGroup(string name, string str)
        {
            SpecisOutput ps = new SpecisOutput("SO2", false, true, false, true, false, true, false);

            ps.name = name;
            if (StrWriter.GetString(str, 1) == "1")
            {
                ps.m_ConPrinted = true;
            }
            else
            {
                ps.m_ConPrinted = false;
            }


            if (StrWriter.GetString(str, 2) == "1")
            {
                ps.m_ConSaved = true;
            }
            else
            {
                ps.m_ConSaved = false;
            }
            if (StrWriter.GetString(str, 3) == "1")
            {
                ps.m_DryPrinted = true;
            }
            else
            {
                ps.m_DryPrinted = false;
            }


            if (StrWriter.GetString(str, 4) == "1")
            {
                ps.m_DrySaved = true;
            }
            else
            {
                ps.m_DrySaved = false;
            }
            if (StrWriter.GetString(str, 5) == "1")
            {
                ps.m_WetPrinted = true;
            }
            else
            {
                ps.m_WetPrinted = false;
            }


            if (StrWriter.GetString(str, 6) == "1")
            {
                ps.m_WetSaved = true;
            }
            else
            {
                ps.m_WetSaved = false;
            }
            if (StrWriter.GetString(str, 7) == "1")
            {
                ps.m_MassSaved = true;
            }
            else
            {
                ps.m_MassSaved = false;
            }

            return ps;
        }

        string name;

        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        bool m_ConPrinted;

        public bool ConPrinted
        {
            get { return m_ConPrinted; }
            set { m_ConPrinted = value; }
        }
        bool m_ConSaved;

        public bool ConSaved
        {
            get { return m_ConSaved; }
            set { m_ConSaved = value; }
        }

        bool m_DryPrinted;

        public bool DryPrinted
        {
            get { return m_DryPrinted; }
            set { m_DryPrinted = value; }
        }
        bool m_DrySaved;

        public bool DrySaved
        {
            get { return m_DrySaved; }
            set { m_DrySaved = value; }
        }

        bool m_WetPrinted;

        public bool WetPrinted
        {
            get { return m_WetPrinted; }
            set { m_WetPrinted = value; }
        }
        bool m_WetSaved;

        public bool WetSaved
        {
            get { return m_WetSaved; }
            set { m_WetSaved = value; }
        }

        bool m_MassSaved;

        public bool MassSaved
        {
            get { return m_MassSaved; }
            set { m_MassSaved = value; }
        }
        private bool m_CalculateSpecies = false;
        /// <summary>
        /// 是否估算污染物
        /// </summary>
        public bool CalculateSpecies
        {
            get { return m_CalculateSpecies; }
            set { m_CalculateSpecies = value; }
        }
        public object Clone()
        {
            return this.MemberwiseClone();
        }
    }

}
